<include file="header" />
<body>
<div class="wraper">
		<div class="header flex-box">
			<a href="javascript:;"></a>
			<span class="text-center">租金缴纳</span>
			<a href="{BEESCRM::U('base/rentFee/payHistory',array('rent_fee_id'=>$rent_fee_id))}" class="iconfont icon-wodejiaoyijilu text-right"></a>
		</div>
	<if condition="$no eq 2">
		<p class="classify">缴费金额</p>
		<div class="form-box box-border">
			<div class="form-list flex-box">
				<span class="field_l">店铺名称：</span>
				<select id="shop_id">
					<volist name="data" id="vo">
						<option value="{BEESCRM:$vo.shop_id}">{BEESCRM:$vo.shop_name}</option>
					</volist>
				</select>
				<span class="triangle"></span>
			</div>
			<div class="form-list lineheight15">
				<p>承租人：&nbsp;&nbsp;&nbsp;&nbsp;{BEESCRM:$rent.real_name}</p>
				<p>联系方式：{BEESCRM:$rent.mobile}</p>
			</div>
		</div>
		<p class="classify">缴费金额</p>
		<div class="form-box box-border">
			<div class="form-list flex-box">
				<span class="field">房租：</span>
				<input type="text" class="form-control" placeholder="请输入缴费金额" name="rent_fee" id="rent_fee" value="">
			</div>
			<div class="form-list flex-box">
				<span class="field">物业：</span>
				<input type="text" class="form-control" placeholder="请输入缴费金额" name="property_fee" id="property_fee" value="">
			</div>
			<div class="form-list flex-box">
				<span class="field">水电：</span>
				<input type="text" class="form-control" placeholder="请输入缴费金额" name="water_elec_fee" id="water_elec_fee" value="">
			</div>
			<div class="form-list flex-box">
				<span class="field">押金：</span>
				<input type="text" class="form-control" placeholder="请输入缴费金额" name="deposit_fee" id="deposit_fee" value="">
			</div>
			<div class="form-list flex-box">
				<span class="field">其他：</span>
				<input type="text" class="form-control" placeholder="请输入缴费金额" name="other_fee" id="other_fee" value="">
			</div>
			<div class="form-list clearfix">
				<p class="pull-right text-red">总计：<label id="total">0.00</label></p>
			</div>

		</div>
		<if condition = "$notice">
			<div class="form-box">
				<div class="form-list flex-box">
					<span class="field text-red ">温馨提示：</span>
					<p class="form-control text-red">{BEESCRM:$notice}</p>
				</div>
				<!--<div class="form-list lineheight15">
					<p class="text-12 text-red">{BEESCRM:$notice}</p>
				</div>-->
			</div>
		</if>
		<div class="container">
			<a href="javascript:void(0);" class="btn text-center" id="charge">立即缴费</a>
		</div>
		<div class="layer-wraper flex-box">
			<div class="main">
				<div class="lists lineheight15">
					<div class="label-btn text-16 text-center">请确认是否付款</div>
				</div>
				<div class="pop-btn">
					<a href="#" class="btn cancel">再看看</a>
					<a href="#" class="btn green-btn submit" data-list_id="{BEESCRM:$data.list_id}">确认付款</a>
				</div>
			</div>
		</div>
	</if>
	<if condition="$no eq 1">
		<div class="container">
			<div class="label">
				<div class="label-mes flex-box">
					<p class="text-22 text-gray">暂无缴费信息</p><br />
				</div>
			</div>
		</div>
	</if>
	<input type="hidden" value="{BEESCRM:$rent_fee_id}" id="id" />
	<input type="hidden" value="{BEESCRM:$rent.user_id}" id="rent_id" />
</div>
<script src="/assets/base/electricityfee/js/jquery-2.1.0.min.js"></script>
<script src="/assets/base/electricityfee/js/jq.utils.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="/assets/bower_components/sweetalert/lib/sweet-alert.min.js"></script>
<link rel="stylesheet" href="/assets/bower_components/sweetalert/lib/sweet-alert.css?v={BEESCRM:$time}">
<script src="/assets/base/common/ajaxgetroominfo.js"></script>
<script>
    $('.tab-prize').on('click','.option',function(){
        if($(this).hasClass('other')){
            $(this).siblings().removeClass('checked');
        }
        else{
            $(this).toggleClass('checked').siblings().removeClass('checked');
        }
    });
    $('#charge').on('click',function(){
        $('.layer-wraper').addClass('layer-show');
    });

    $('.cancel').on('click',function(){
        $('.layer-wraper').removeClass('layer-show');
    });
	$(document).on('click','.submit',function(){
		var rent_fee_id = $('#id').val();
		var rent_user = $('#rent_id').val();
        var rent_fee = $("#rent_fee").val();
        var property_fee = $("#property_fee").val();
        var water_elec_fee = $("#water_elec_fee").val();
        var deposit_fee = $("#deposit_fee").val();
        var other_fee = $("#other_fee").val();
        var shop_id = $("#shop_id").val();
        if(!shop_id){
            $('.layer-wraper').removeClass('layer-show');
            $.alert('error','参数错误');
            return false;
		}
        if(rent_fee){
            if(isNaN(rent_fee)){
                $("#rent_fee").val('');
                $('.layer-wraper').removeClass('layer-show');
                $.alert('error','请输入有效数字');
                return false;
            }
        }
        if(property_fee){
            if(isNaN(property_fee)){
                $("#property_fee").val('');
                $('.layer-wraper').removeClass('layer-show');
                $.alert('error','请输入有效数字');
                return false;
            }
        }
        if(water_elec_fee){
            if(isNaN(water_elec_fee)){
                $("#water_elec_fee").val('');
                $('.layer-wraper').removeClass('layer-show');
                $.alert('error','请输入有效数字');
                return false;
            }
        }
        if(deposit_fee){
            if(isNaN(deposit_fee)){
                $("#deposit_fee").val('');
                $('.layer-wraper').removeClass('layer-show');
                $.alert('error','请输入有效数字');
                return false;
            }
        }
        if(other_fee){
            if(isNaN(other_fee)){
                $("#other_fee").val('');
                $('.layer-wraper').removeClass('layer-show');
                $.alert('error','请输入有效数字');
                return false;
            }
        }
		/*var str = '&rent_fee_id='+rent_fee_id + '&rent_fee='+rent_fee +'&property_fee=' +property_fee +'&water_elec_fee='+water_elec_fee +'&deposit_fee='+deposit_fee+'&other_fee='+other_fee;
		var url = "/index.php?g=base&m=rentFee&a=pay"+str;
		window.location.href=url;*/
        payOrder(rent_user,shop_id,rent_fee_id,rent_fee,property_fee,water_elec_fee,deposit_fee,other_fee);
    });
    function payOrder(rent_user,shop_id,rent_fee_id,rent_fee,property_fee,water_elec_fee,deposit_fee,other_fee){
		var data ={};
		data.rent_user = rent_user;
        data.shop_id = shop_id;
        data.rent_fee = rent_fee;
        data.property_fee = property_fee;
        data.water_elec_fee = water_elec_fee;
        data.deposit_fee = deposit_fee;
        data.other_fee = other_fee;
        $.ajax({
            'url': "/base/rentFee/orderPay/rent_fee_id/"+rent_fee_id,
            'data': data,
            'dataType':'json',
            'type': 'POST',
            'async': false,
            success: function(data) {
                if (data.status == 'S') {
                    $('.layer-wraper').removeClass('layer-show');
                    var wxpay = $.parseJSON(data.wxpay);
                    pay(wxpay);
                }else{
                    $('.pop2').removeClass('layer-show');
                    $('.layer-wraper').removeClass('layer-show');
                    $.alert('error',data.message);
                    return false;
                }
            }
        });
    }


    //微支付
    function pay(wxpay){
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                wxpay,
                function(res){
                    WeixinJSBridge.log(res.err_msg);
                    if(res.err_msg == "get_brand_wcpay_request:ok"){
                        paySuccess();
                    }else if(res.err_msg == "get_brand_wcpay_request:cancel"){

                        return false;
                    }else{
                        $.alert('error','调用微支付失败');
                        $('.layer-wraper').removeClass('layer-show');
                        return false;
                    }
                }
            );
        }
    }

    function paySuccess(){
        var rent_fee_id = $('#id').val();
        location.href = "/base/rentFee/payHistory?rent_fee_id="+rent_fee_id;
    }

    //页面刷新
    function reload(){
        setTimeout('location.reload()', 2000);
    }
    $("input").blur(function(){
        var rent_fee = $("#rent_fee").val();
        var property_fee = $("#property_fee").val();
		var water_elec_fee = $("#water_elec_fee").val();
		var deposit_fee = $("#deposit_fee").val();
		var other_fee = $("#other_fee").val();
		if(rent_fee){
		    if(isNaN(rent_fee)){
                $("#rent_fee").val('');
                $.alert('error','请输入有效数字');
			}
		}
        if(property_fee){
            if(isNaN(property_fee)){
                $("#property_fee").val('');
                $.alert('error','请输入有效数字');
            }
        }
        if(water_elec_fee){
            if(isNaN(water_elec_fee)){
                $("#water_elec_fee").val('');
                $.alert('error','请输入有效数字');
            }
        }
        if(deposit_fee){
            if(isNaN(deposit_fee)){
                $("#deposit_fee").val('');
                $.alert('error','请输入有效数字');
            }
        }
        if(other_fee){
            if(isNaN(other_fee)){
                $("#other_fee").val('');
                $.alert('error','请输入有效数字');
            }
        }
        var total = 0.00;
        total = total + Number(rent_fee) + Number(property_fee) + Number(water_elec_fee) + Number(deposit_fee) + Number(other_fee);
        total = Number(total).toFixed(2);
		$("#total").html(total);
    });
</script>
</body>
</html>